package com.xbongbong.sys.model.impl;

import com.xbongbong.sys.constant.PaasFormTableNameConstant;
import com.xbongbong.sys.domain.dao.ProPermissionDao;
import com.xbongbong.sys.domain.entity.ProPermissionEntity;
import com.xbongbong.sys.help.SysEnvHelp;
import com.xbongbong.sys.model.ProPermissionModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * pro权限（saas部分） model
 *
 * @author kaka
 * @version v1.0
 * @date 2019/3/9 17:55
 * @since v1.0
 */
@Service("proPermissionModel")
public class ProPermissionModelImpl implements ProPermissionModel {

    @Resource
    private ProPermissionDao permissionDao;
    @Resource
    private SysEnvHelp sysEnvHelp;

    @Override
    public Integer insert(ProPermissionEntity entity) {
        return permissionDao.insert(entity);
    }

    @Override
    public Integer update(ProPermissionEntity entity) {
        return permissionDao.update(entity);
    }

    @Override
    public ProPermissionEntity getByKey(Integer key) {
        return permissionDao.getByKey(key);
    }

    @Override
    public ProPermissionEntity getByAlias(String alias) {
        if (sysEnvHelp.isGrayEnvironment()) {
            return permissionDao.getByAlias(alias, PaasFormTableNameConstant.TB_PRO_PERMISSION_GRAY);
        } else {
            return permissionDao.getByAlias(alias, PaasFormTableNameConstant.TB_PRO_PERMISSION);
        }
    }

    @Override
    public List<ProPermissionEntity> findEntitys(Map<String, Object> param) {
        if (sysEnvHelp.isGrayEnvironment()) {
            return permissionDao.findEntitys(param, PaasFormTableNameConstant.TB_PRO_PERMISSION_GRAY);
        } else {
            return permissionDao.findEntitys(param, PaasFormTableNameConstant.TB_PRO_PERMISSION);
        }
    }

    @Override
    public Integer getEntitysCount(Map<String, Object> param) {
        if (sysEnvHelp.isGrayEnvironment()) {
            return permissionDao.getEntitysCount(param, PaasFormTableNameConstant.TB_PRO_PERMISSION_GRAY);
        } else {
            return permissionDao.getEntitysCount(param, PaasFormTableNameConstant.TB_PRO_PERMISSION);
        }
    }

    @Override
    public List findEntitysWithoutSub(Map<String, Object> param) {
        return null;
    }

    @Override
    public List<Integer> findEntityIds(Map<String, Object> param) {
        if (sysEnvHelp.isGrayEnvironment()) {
            return permissionDao.findEntityIds(param, PaasFormTableNameConstant.TB_PRO_PERMISSION_GRAY);
        } else {
            return permissionDao.findEntityIds(param, PaasFormTableNameConstant.TB_PRO_PERMISSION);
        }
    }

    @Override
    public List<String> getByIdIn(Collection<Integer> idIn) {
        if (sysEnvHelp.isGrayEnvironment()) {
            return permissionDao.getAliasByIdIn(idIn, PaasFormTableNameConstant.TB_PRO_PERMISSION_GRAY);
        } else {
            return permissionDao.getAliasByIdIn(idIn, PaasFormTableNameConstant.TB_PRO_PERMISSION);
        }
    }

    @Override
    public void updateBatch(List<ProPermissionEntity> proPermissionEntityList) {
        permissionDao.updateBatch(proPermissionEntityList);
    }

    @Override
    public void updateName(Integer id, String name) {
        permissionDao.updateName(id, name);
    }
}
